<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :footer="null"
    cancelText="关闭">

    <table id="table_report" class="table table-striped table-bordered table-hover">

           			<tr>
           				<td style="width:90px;text-align: right;padding-top: 80px;">基本信息:</td>
           				<td>
           					<p style="float: left;">


             停车场计费规则id(对应charge_rules表主键id)：<span id="chargeRulesId" >
           {{result.chargeRulesId }}
                    </span><br>


             计费类型  1按次 2按时段：<span id="chargeType" >
           {{result.chargeType }}
                    </span><br>


             起始时间：<span id="startTime" >
           {{result.startTime }}
                    </span><br>


             过期时间：<span id="endTime" >
           {{result.endTime }}
                    </span><br>


             一次收费金额(单位分)：<span id="onceMoney" >
           {{result.onceMoney }}
                    </span><br>


             时段最高收费限额(单位分)：<span id="rangeLimit" >
           {{result.rangeLimit }}
                    </span><br>


             时段最高收费限额是否启用  1启用 2未启用：<span id="rangeLimitEnable" >
           {{result.rangeLimitEnable }}
                    </span><br>


             首计时单位（分钟）：<span id="firstUnit" >
           {{result.firstUnit }}
                    </span><br>


             首计时单位收费金额（单位分）：<span id="firstMoney" >
           {{result.firstMoney }}
                    </span><br>


             每计时单位（分钟）：<span id="timeUnit" >
           {{result.timeUnit }}
                    </span><br>


             每计时单位收费金额（单位分）：<span id="moneyUnit" >
           {{result.moneyUnit }}
                    </span><br>


             不足时段计费 1首计时计费 2不计费 3本时段计费：<span id="notEnough" >
           {{result.notEnough }}
                    </span><br>


             超出时段计费 1首计时计费 2不计费 3本时段计费：<span id="goBeyond" >
           {{result.goBeyond }}
                    </span><br>


             创建人id：<span id="createUserId" >
           {{result.createUserId }}
                    </span><br>


             创建人名称：<span id="createUserName" >
           {{result.createUserName }}
                    </span><br>


             修改人id：<span id="updateUserId" >
           {{result.updateUserId }}
                    </span><br>


             修改人名称：<span id="updateUserName" >
           {{result.updateUserName }}
                    </span><br>


             修改时间：<span id="updateTime" >
           {{result.updateTime }}
                    </span><br>

  创建时间：<span id="createTime" >
           {{result.createTime }}
                    </span><br>
	</p>
			</td>
                			</tr>

                				<tr>
                                    <td style="width:90px;text-align: right;padding-top: 60px;">详情:</td>
                                    <td>
                                        <p style="float: left;">


                                        </p>
                                    </td>
                            	</tr>

                			<tr>
                				<td style="text-align: center;" colspan="10">
                                 <a-button type="primary" @click="close">关闭</a-button>
                				</td>
                			</tr>
                		</table>

  </a-modal>
</template>

<script>
  import { httpAction } from '@api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"

  export default {
    name: "ChargeRulesModuleModal",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
         result: {

                },
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        chargeRulesId:{rules: [{ required: true, message: '请输入停车场计费规则id(对应charge_rules表主键id)!' }]},
        },
        url: {
          add: "/parking/chargeRulesModule/add",
          edit: "/parking/chargeRulesModule/edit",
        },
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
             Object.assign(this.result, record);
              this.visible = true;
            },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.startTime = formData.startTime?formData.startTime.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.endTime = formData.endTime?formData.endTime.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.updateTime = formData.updateTime?formData.updateTime.format('YYYY-MM-DD HH:mm:ss'):null;

            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })



          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style lang="less" scoped>

</style>